<!--面试考核-->
<template>
<div>
  <div class="table-body-box">
    <el-table
        ref="multipleTable"
        :data="arryList"
        :border="tableoption.tableBorder"
        tooltip-effect="dark">
      <el-table-column
          label="ID"
          align="center"
          width="100"
          prop="id">
      </el-table-column>
      <el-table-column
          label="名称"
          align="center"
          prop="title">
      </el-table-column>
      <el-table-column
          label="教师名称"
          align="center">
        <template slot-scope="scope">
          <el-input v-model="scope.row.parent_title" auto-complete="off" placeholder="填写教师名称" type="textarea"
                    :autosize="autosize" v-if="scope.row.edit"></el-input>
          <span v-else>{{ scope.row.parent_title }}</span>
        </template>
      </el-table-column>
      <el-table-column
          label="家长名称"
          align="center">
        <template slot-scope="scope">
          <el-input v-model="scope.row.user_title" auto-complete="off" placeholder="填写家长名称" type="textarea"
                    :autosize="autosize" v-if="scope.row.edit"></el-input>
          <span v-else>{{ scope.row.user_title }}</span>
        </template>
      </el-table-column>
      <el-table-column
          label="对应人格"
          align="center"
          prop="title">
        <template slot-scope="scope">
          {{ scope.row.character.name }}-{{ scope.row.character.id }}号
        </template>
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
          width="160">
        <template slot-scope="scope">
          <el-button size="small" @click="showEditFn(scope.row,scope.$index)" v-if="!scope.row.edit">编辑</el-button>
          <el-button size="small" @click="showEditFn(scope.row,scope.$index)" v-else type="primary">保存</el-button>
          <!--                <el-button size="small" @click="showDetail(scope.row.id)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
  </div>
  <!--工具条 分页-->
  <el-col :span="24" class="toolbar">
    <el-pagination
        background
        :page-size="page.pagesize"
        :current-page="page.pageindex"
        layout="total, prev, pager, next"
        :total="page.total"
        @current-change="handleSizeChange"></el-pagination>
  </el-col>
</div>
</template>

<script>
import {pagination, tableoption, yeartime} from '@/utils/util.js'

export default {
  components: {},
  data() {
    return {
      tableoption: tableoption,
      autosize: {minRows: 2, maxRows: 4},
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [], // 数据列表
    }
  },
  created() {
    this.InitFn()
  },
  methods: {
    // 初始化
    async InitFn() {
      let data = await this.$fetch(this.api.acquisition.setting.personality, {p: this.page.pageindex});
      console.log('data:', data)
      if (!data.code) {
        for (let item of data.list.data) {
          item.eidt = false
        }
        this.arryList = data.list.data
        this.page.total = data.list.total
      }
    },
    showEditFn(row, index) {
      let option = this.getJson(row)
      if (option.edit) {
        this.editTitle(option)
      } else {
        option.edit = true;
      }
      this.$set(this.arryList, index, option)
    },
    async editTitle(option) {
      let option_ = {
        id: option.id, // 	整型 	必填 	1 	- 	ID
        title: option.title, 	// 整型 	必填 	1 	- 	内容
        character_id: option.character_id, 	// 整型 	必填 	1 	- 	对应人格id
        user_title: option.user_title,
        parent_title: option.parent_title
      }
      let data = await this.$post(this.api.acquisition.setting.edit_personality, option_);
      if (!data.code) {
        option.edit = false;
      }
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    cateListFn() {
      this.$fetch(this.api.cate_list, {
        p: 1
      }).then((response) => {
        if (response.code === 0) {
          for (let i in response.list.data) {
            this.tableList.push(response.list.data[i])
          }
        } else {
        }
      }).catch((err) => {
        console.log(err)
      })
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    showDetail(id) {
      this.resumeId = id
      this.resumeVisible = true
    },
    handleClick(tab, event) {
      if (this.activeName !== this.activeNamechange) {
        this.activeNamechange = this.activeName;
        this.page.pageindex = 1
        this.arryList = []
        this.InitFn()
      }
    },
    // 获取岗位信息
    async JobFn() {
      let data = await this.$fetch(this.api.recruit.job.index, {p: 1});
      this.jobList = data.list.data;
    },
    searchFn(option) {
      if (option === 'refresh') {
        this.searchForm.name = ''
        this.searchForm.job_id = ''
      }
      this.page.pageindex = 1;
      this.InitFn()
    }
  },
  mounted() {
  }
}
</script>
<style>
.not-list {
  text-align: center;
  padding: 50px;
  color: #999;
  font-size: 16px;
}
</style>
